package com.woniuxy.microstockserver.mapper;

import com.woniuxy.microstockserver.bean.EnterStockBean;
import com.woniuxy.microstockserver.bean.EnterStockGoodsDetailBean;
import com.woniuxy.microstockserver.bean.PageRequestBean;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
/**
 * @author 赵雄伟
 *入库模块持久层
 */
@Mapper
public interface EnterStockMapper {

    /**
     *分页、模糊、分类查询所有入库单
     * @param pageRequestBean
     * @param enterStockBean
     * @return
     */
    List<EnterStockBean> findAllEnterStockBean(@Param("p") PageRequestBean pageRequestBean, @Param("es") EnterStockBean enterStockBean);

    /**
     * 新增入库单：含正常入库，销售退货入库，采购入库
     * @param enterStockBean
     * @return
     */
    @Insert("insert into t_enterstock_info (es_num,fk_esstore_id,es_type,es_amount,es_handle,es_makelist_person,es_makelist_date,es_audit_status,delete_status,es_remarks) values(#{es.esNum},#{es.esStoreId},#{es.esType},#{es.esAmount},#{es.esHandle},#{es.esMakeListPerson},#{es.esMakeListDate},#{es.esAuditStatus},#{es.deleteStatus},#{es.esRemarks})")
    @Options(useGeneratedKeys = true, keyProperty = "es.id" ,keyColumn="id")
    Long saveEnterStockBean(@Param("es") EnterStockBean enterStockBean);


    /**
     * 根据id查询入库单的详情
     * @param id
     * @return
     */
    @Results({
            @Result(id=true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "esNum",column = "es_num",javaType = String.class),
            @Result(property = "esStoreId",column = "fk_esstore_id",javaType = Long.class),
            @Result(property = "esType",column = "es_type",javaType = Integer.class),
            @Result(property = "esAmount",column = "es_amount",javaType = Integer.class),
            @Result(property = "esHandle",column = "es_handle",javaType = String.class),
            @Result(property = "esMakeListPerson",column = "es_makelist_person",javaType = String.class),
            @Result(property = "esMakeListDate",column = "es_makelist_date",javaType = Date.class),
            @Result(property = "esAuditStatus",column = "es_audit_status",javaType = Integer.class),
            @Result(property = "deleteStatus",column = "delete_status",javaType = Byte.class),
            @Result(property = "esRemarks",column = "es_remarks",javaType = String.class)
    })
    @Select("select * from t_enterstock_info where id = #{id}")
    EnterStockBean findEnterStockAndGoodsDetail(@Param("id") Long id);

    /**
     * 修改入库单
     * @param enterStockBean
     * @return
     */
    @Update("<script>" +
            "update t_enterstock_info" +
            "<set>" +
            "<if test='es.esNum != null'>" +
            " es_num = #{es.esNum}," +
            "</if>" +
            "<if test='es.esStoreId != null'>" +
            " fk_esstore_id = #{es.esStoreId}," +
            "</if>" +
            "<if test='es.esType != null'>" +
            " es_type = #{es.esType}," +
            "</if>" +
            "<if test='es.esAmount != null'>" +
            " es_amount = #{es.esAmount}," +
            "</if>" +
            "<if test='es.esHandle != null'>" +
            " es_handle = #{es.esHandle}," +
            "</if>" +
            "<if test='es.esMakeListPerson != null'>" +
            " es_makelist_person = #{es.esMakeListPerson}," +
            "</if>" +
            "<if test='es.esMakeListDate != null'>" +
            " es_makelist_date = #{es.esMakeListDate}," +
            "</if>" +
            "<if test='es.esAuditStatus != null'>" +
            " es_audit_status = #{es.esAuditStatus}," +
            "</if>" +
            "<if test='es.deleteStatus != null'>" +
            " delete_status = #{es.deleteStatus}," +
            "</if>" +
            "<if test='es.esRemarks != null'>" +
            " es_remarks = #{es.esRemarks}," +
            "</if>" +
            "</set>" +
            "where id = #{es.id}" +
            "</script>")
    Long upadteEnterStockBean(@Param("es") EnterStockBean enterStockBean);

}
